package com.acaomei.skype.common;

import java.io.Serializable;

public class ResultVo implements Serializable {

	private static final long serialVersionUID = 7763120724201548591L;
	
	public static final String SUCCESS = "success";
	public static final String SUCCESS_CODE = "200";
	public static final String SUCCESS_DEFAULT_COUNT = "1";
	public static final String SUCCESS_DEFAULT_MSG = "成功";
    
	public static final String ERROR = "error";
	public static final String ERROR_CODE = "500";
	public static final String ERROR_DEFAUL_COUNT = "0";
	public static final String ERROR_DEFAULT_MSG = "失败";
	
	public  static <T> Result<T> successResult(){
		return new Result<T>(SUCCESS, SUCCESS_DEFAULT_MSG, null, null, SUCCESS_CODE);
	}
	
	public static <T> Result<T> successResult(T data){
		return successResult(SUCCESS_DEFAULT_COUNT,data);
	}
	
	
	public static <T> Result<T> successResult(String count, T data){
		return new Result<T>(SUCCESS, SUCCESS_DEFAULT_MSG, count, data, SUCCESS_CODE);
	}
	
	/**
	 * 描述: 只是消息提醒
	 * @Title: successResult   
	 * @param count
	 * @param data
	 * @return Result<String>
	 */
	public static <T> Result<T> successResultMessage(String message){
		return new Result<T>(SUCCESS, message, null, null, SUCCESS_CODE);
	}
	
	public static <T> Result<T> successResultMessage(String message, T data){
		return new Result<T>(SUCCESS, message, null, data, SUCCESS_CODE);
	}
	
	public static <T> Result<T> errorResult()
	{
		return errorResult(ERROR_DEFAULT_MSG,ERROR_CODE);
	}
	
	public static <T> Result<T> errorResult(String msg)
	{
		return errorResult(msg,ERROR_CODE);
	}
	
	public static <T> Result<T> errorResult(String msg,  String code)
	{
		return new Result<T>(ERROR, msg, ERROR_DEFAUL_COUNT,  null, code);
	}
	
	/**
	 * 描述: 只是消息提醒
	 * @Title: successResult   
	 * @param count
	 * @param data
	 * @return Result<String>
	 */
	public static <T> Result<T> errorResultMessage(String message){
		return new Result<T>(ERROR, message, ERROR_DEFAUL_COUNT, null, ERROR_CODE);
	}

	/**
	 * 判断一个Result是不是成功的Result
	 * @param result 待判断的Result
	 * @return
	 */
	public static boolean isSuccessResult(Result<?> result){
		if(result == null) throw new NullPointerException("result 不能为空");
		return SUCCESS_CODE.equals(result.getCode());
	}
	
	/**
	 * 判断一个Result是不是失败的Result
	 * @param result 待判断的Result
	 * @return
	 */
	public static boolean isFailedResult(Result<?> result){
		return !isSuccessResult(result);
	}

}
